package com.zulu.watchall.phone;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
import com.zulu.watchall.R;
import com.zulu.watchall.constant.Constants;
import com.zulu.watchall.constant.DevKey;
import com.zulu.watchall.custom.CustomTextView;

public class VideoActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{

	private String videoId = "";
	private CustomTextView mTxtVideoTitle;
	
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.activity_video);
		
		YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
		youTubePlayerView.initialize(DevKey.API_KEY, this);
		
		initCustomTitleBar();
		initView();
		
		bundle = getIntent().getExtras();
		if(bundle!=null) {
			videoId = bundle.getString(Constants.ExtrasConstants.VIDEO_ID);
			mTxtVideoTitle.setText(bundle.getString(Constants.ExtrasConstants.VIDEO_TITLE));
		}
	}
	
	/**
	 * set title for custom title bar
	 */
	private void initCustomTitleBar() {
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
		CustomTextView tvTitle = (CustomTextView)findViewById(R.id.txt_title_bar);
		tvTitle.setText("Home");
		ImageView bugger = (ImageView)findViewById(R.id.btn_side_menu);
		bugger.setVisibility(View.GONE);
	}
	
	private void initView() {
		mTxtVideoTitle = (CustomTextView)findViewById(R.id.txt_video_title);
	}
	
	@Override
	public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
		Toast.makeText(getApplicationContext(), "onInitializationFailure()",
				Toast.LENGTH_LONG).show();
	}

	@Override
	public void onInitializationSuccess(Provider arg0, YouTubePlayer player,
			boolean wasRestored) {
		if (!wasRestored) {
			player.cueVideo(videoId);
		}
	}

}
